package bw.util;

import java.util.*;
import java.io.*;
import java.util.logging.*;
import java.text.*;

public class LogFormatter extends java.util.logging.Formatter
{
    private SimpleDateFormat _dateFormat = null;

    public LogFormatter ()
    {
        super();

        _dateFormat = new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss.SSS" );
    }

    public String format ( LogRecord record )
    {
        StringBuffer buf = new StringBuffer();
        buf.append( _dateFormat.format( DateFactory.getInstance().getDate() ) );
        buf.append( " : " );
        //buf.append( record.getLevel() );
        //buf.append( " : " );
        buf.append( record.getMessage() );
        buf.append( "\n" );

        Throwable throwable = record.getThrown();
        if (throwable != null)
        {
            StringWriter sink = new StringWriter();
            throwable.printStackTrace( new PrintWriter( sink, true ) );
            buf.append( sink.toString() ).append( "\n" );
        }

        return buf.toString();
    }
}